package com.spzx.product.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.domain.vo.CategoryBrandDetailVo;
import com.spzx.product.domain.vo.ProductSpecVo;
import com.spzx.product.mapper.ProductSpecMapper;
import com.spzx.product.service.CategoryBrandService;
import com.spzx.product.service.CategoryService;
import com.spzx.product.service.ProductSpecService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, ProductSpec> implements ProductSpecService {

    @Autowired
    ProductSpecMapper productSpecMapper;
    @Autowired
    CategoryBrandService categoryBrandService;
    @Override
    public List<ProductSpecVo> selectProductSpecList(ProductSpec productSpec) {
        return productSpecMapper.selectProductSpecList(productSpec);
    }

    @Override
    public ProductSpecVo selectProductSpecById(Long id) {
        ProductSpec productSpec = productSpecMapper.selectById(id);

        Long categoryId = productSpec.getCategoryId();
        String s = productSpecMapper.selectCategoryName(categoryId);

        Map<String,Long> map = categoryBrandService.getDetailByC3Id(categoryId);
        ArrayList<Long> arrayList = new ArrayList<>();
        arrayList.add(map.get("c1Id"));
        arrayList.add(map.get("c2Id"));
        arrayList.add(map.get("c3Id"));

        productSpec.setCategoryIdList(arrayList);
        ProductSpecVo vo = new ProductSpecVo();
        BeanUtils.copyProperties(productSpec,vo);
        vo.setCategoryName(s);
        return vo;
    }

    @Override
    public List<ProductSpec> getSpecList(Long categoryId) {
      return   productSpecMapper.selectList(new LambdaQueryWrapper<ProductSpec>().eq(ProductSpec::getCategoryId,categoryId));


    }

}
